package com.fuxue.controller.server;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fuxue.dto.ReceptDTO;
import com.fuxue.entity.Messge;
import com.fuxue.result.Result;
import com.fuxue.service.HelpService;
import com.fuxue.service.RanklistService;
import com.fuxue.vo.ForumVO;
import com.fuxue.websocket.WebSocketServer;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/users/server/help")
@Slf4j
@Api(tags = "服务者论坛有关页面")
public class HelpController {
    @Autowired
    private HelpService helpService;
    @Autowired
    private WebSocketServer webSocketServer;
    @Autowired
    private ObjectMapper objectMapper;
    @GetMapping("/select")
    private Result<List<ForumVO>>getall()
    {
        log.info("随机数上场");
        List<ForumVO>list = helpService.getSelect();
        return Result.success(list);
    }
    @PutMapping("/GetAnswer")
    private Result getAnswer(@RequestBody  ReceptDTO receptDTO)
    {

          log.info("获取悬赏，参数为{}",receptDTO);
          helpService.updateQuestion(receptDTO);
          return Result.success();
    }
    @PostMapping("/messege")
    private Result writemessege(@RequestBody Messge messge) throws JsonProcessingException {
        String ss = objectMapper.writeValueAsString(messge);
        webSocketServer.sendToAllClient(ss);
        return Result.success();
    }

}
